package top.lshaci.learning.springboot.jpaquerydsl.config;

import cn.hutool.extra.spring.SpringUtil;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import top.lshaci.learning.springboot.jpaquerydsl.core.DslUtil;

import javax.persistence.EntityManager;

/**
 * QueryDslConfig
 *
 * @author lshaci
 * @since 1.0.0
 */
@Configuration
@Import(SpringUtil.class)
public class QueryDslConfig {

    @Bean
    public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) {
        JPAQueryFactory jpaQueryFactory = new JPAQueryFactory(entityManager);
        DslUtil.setJpaQueryFactory(jpaQueryFactory);
        return jpaQueryFactory;
    }
}
